home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Demos / Extend 3.0 Demo / Demo Libraries / Demo Animation Lib / Demo Animation Lib.rsrc / MODL_9930_Animate Value < prev    next >
Encoding:
Text File  |  1994-06-22  |  4.1 KB  |  191 lines

  1. //    Animate Value block; Animation library
  2. //    This block animates a value from a value connector.
  3. //    Copyright © 1992-1994 by Imagine That,Inc.
  4. //    All Rights Reserved.
  5.  
  6. //        modified
  7. //            12/17/92 JSL added theObj to else clause
  8. //            1/27/94     DJK removed time delay on displaying value -> added check to see if current value was == to last
  9. //            4/25/94  DJK changed initialization to hide if animation not on and reset values to  0 if animation is on
  10.  
  11. integer theObj, thePattern, useHObject, alreadyShown;
  12. real    lastHeight;
  13. integer    oldTicks;
  14. real    oldvalue;
  15.  
  16. procedure GetPatternAndColor()
  17. {
  18. if (Solid) thePattern = 1;
  19.     else if (Dark) thePattern = 3;
  20.     else if (Medium) thePattern = 4;
  21.     else thePattern = 23;
  22. if (Black) AnimationColor(theObj, 0, 0, 0, thePattern);
  23. else if (White) AnimationColor(theObj, 0, 0, 65535, thePattern);
  24. else if (Red) AnimationColor(theObj, 0, 65535, 65535, thePattern);
  25. else if (Orange) AnimationColor(theObj, 5461, 65535, 65535, thePattern);
  26. else if (Yellow) AnimationColor(theObj, 10923, 65535, 65535, thePattern);
  27. else if (Green) AnimationColor(theObj, 21845, 65535, 65535, thePattern);
  28. else if (Blue) AnimationColor(theObj, 43691, 65535, 65535, thePattern);
  29. else if (Purple) AnimationColor(theObj, 54614, 65535, 65535, thePattern);
  30. }
  31.  
  32. // This message occurs for each step in the simulation.
  33. on simulate
  34. {
  35. real    theHeight;
  36. integer    newTicks;
  37.  
  38. Con1Out=Con1In;        //Pass data through
  39.  
  40. if (showValue)
  41.     {
  42.     if ( !useHObject)    // set it to internal
  43.         theObj = 2;
  44.         
  45.     newTicks = TickCount();
  46. //    if (newTicks-oldTicks > 30)
  47.     if(con1In != oldValue)
  48.         {
  49. //        oldTicks = newTicks;
  50.         oldValue = Con1In;
  51.         GetPatternAndColor();
  52.         AnimationText(theObj, Con1in);
  53.         AnimationShow(theObj);
  54.         }
  55.     }
  56. else if (animateLevel)
  57.     {
  58.     if ( !useHObject)    // set it to internal
  59.         theObj = 1;
  60.         
  61.     theHeight = (Con1In - Min)/(Max - Min);
  62.     if (theHeight != lastHeight)
  63.         {
  64.         GetPatternAndColor();
  65.         AnimationLevel(theObj, theHeight);
  66.         AnimationShow(theObj);
  67.         lastHeight = theHeight;
  68.         }
  69.     }
  70. else                    //Selected AnimateFlash
  71.     {
  72.     if (Con1In >= Thresh)
  73.         {
  74.         if (! useHObject)    // set it to internal
  75.             {
  76.             if (FlashText)
  77.                 theObj = 2;
  78.             else
  79.                 theObj = 1;
  80.             }
  81.             
  82.         if (playMovie)
  83.             {
  84.             while (waitDone && ! AnimationMovieFinish(theObj))
  85.                 ;    // wait here to replay
  86.                 
  87.             if (AnimationMovieFinish(theObj))    // if it's done, start again
  88.                 AnimationMovie(theObj, movieName, speed, TRUE, TRUE);
  89.             }
  90.         else if (! alreadyShown)        // not up yet - prevent flashing
  91.             {
  92.             GetPatternAndColor();
  93.             
  94.             if (FlashBox)
  95.                 AnimationRectangle(theObj);
  96.             else if (FlashCircle)
  97.                 AnimationOval(theObj);
  98.             else if (FlashText)
  99.                 AnimationText(theObj, TextToFlash);
  100.             else if (ShowPicture)
  101.                 AnimationPicture(theObj, pictureName, TRUE);
  102.                 
  103.             AnimationShow(theObj);
  104.             alreadyShown = TRUE;
  105.             }
  106.         }
  107.     else
  108.         {
  109.         if (! useHObject)    // set it to internal        12/17/92 JSL
  110.             {
  111.             if (FlashText)
  112.                 theObj = 2;
  113.             else
  114.                 theObj = 1;
  115.             }
  116.  
  117.         AnimationHide(theObj, FALSE);
  118.         alreadyShown = FALSE;
  119.         }
  120.     }
  121. }
  122.  
  123. // see if the user has entered an H-Block animation object
  124. on checkData
  125. {
  126. if (noValue(objNum))
  127.     useHObject    = FALSE;    // blank means use our internal icon objects
  128. else
  129.     {
  130.     theObj        = -objnum;    // negate it for H-Block animation object
  131.     useHObject    = TRUE;
  132.     }
  133.  
  134. if (Max<=Min)
  135.     {
  136.     UserError("The maximum must be greater than the minimum to use animate \
  137. level in Animate Value block "+myBlockNumber());
  138.     Abort;
  139.     }
  140. }
  141.  
  142.  
  143. // Initialize any simulation variables.
  144. on initsim
  145. {
  146.     if(useHObject == TRUE)
  147.     {
  148.         if(animationOn)
  149.         {
  150.             if(showValue)
  151.             {
  152.                 AnimationText(theObj, "");
  153.                 animationShow(theObj);
  154.             }
  155.             else if(animateLevel)
  156.             {
  157.                 GetPatternAndColor();
  158.                 AnimationLevel(theObj, 0);
  159.                 AnimationShow(theObj);
  160.             }
  161.         }
  162.         else
  163.         {
  164.             AnimationText(theObj, "");
  165.             animationHide(theObj, FALSE);
  166.         }
  167.     }
  168.     else
  169.     {
  170.         AnimationHide(1, FALSE);    // JSL hide all, for animation off, and unused types
  171.         AnimationHide(2, FALSE);
  172.     }
  173.     
  174. lastHeight = -1000;        // JSL so that we don't save it from last run
  175. alreadyShown = FALSE;
  176. oldTicks = 0;
  177. }
  178.  
  179. // Initialize any block variables.
  180. on createBlock
  181. {
  182. Thresh            = 0.5;
  183. FlashBox        = TRUE;
  184. Black            = TRUE;
  185. Solid            = TRUE;
  186. TextToFlash        = "Some text";
  187. Max                = 1.0;
  188. Min                = -1.0;
  189. speed = 1.0;
  190. oldvalue        = 0.0;
  191. }